//
//  ZYMainViewController.swift
//  ZYSinaWeibo
//
//  Created by 陟岳 on 16/5/19.
//  Copyright © 2016年 陟岳. All rights reserved.
//

import UIKit

class ZYMainViewController: UITabBarController {
    //重写ViewDidLoad方法
    override func viewDidLoad() {
        
        super.viewDidLoad()
        
        addChildViewControllers()
        
        let mainTabBar = ZYTabBar()

        //添加点击事件
        mainTabBar.plusBtn.addTarget(self, action: #selector(plusBtnClick), forControlEvents: .TouchUpInside)
        //只能用KVC来赋值
        setValue(mainTabBar, forKey: "tabBar")
    }
    
    
    //加号按钮点击方法
    @objc private func plusBtnClick() {
    
        print("点我")
    
    }
    //添加子控制器方法
    private func addChildViewControllers() {
    
        addChildViewController(ZYHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(ZYMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(ZYDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ZYProfileTableViewController(), title: "我的", imageName: "tabbar_profile")
    
    }
    
    private func addChildViewController(vc: UIViewController, title: String, imageName: String) {
    
//        vc.tabBarItem.title = title
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        vc.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3)
//        vc.tabBarItem.imageInsets = UIEdgeInsets(top: -5, left: 0, bottom: 5, right: 0)
    
        //内嵌navigationController
        let nav = ZYBaseNavigationController(rootViewController: vc)
        addChildViewController(nav)
    }
    
    
    

}
